class Solution {
public:
    int findSubstringInWraproundString(string s) {
        int len = 1;
        int n = s.size();
        vector<int> dp(26, 0);
        int p = s[0] - 'a';
        dp[p] = 1;
        for (int i = 1; i < n; i++)
        {
            int tmp = s[i] - 'a';
            if (s[i] - s[i - 1] == 1 || (s[i - 1] == 'z' && s[i] == 'a'))
                len++;
            else
                len = 1;
            dp[tmp] = max(dp[tmp], len);
        }

        int ans = 0;
        for (int q : dp)
            ans += q;

        return ans;
    }
};